/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.dusa.worklog.viewer;

import cz.dusa.worklog.datalib.Project;
import java.util.List;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Node;

/**
 *
 * @author vdusa
 */
class ProjectChildFactory  extends ChildFactory<Project>{
    private final List<Project> projectList;

    public ProjectChildFactory(List<Project> resultList) {
        this.projectList = resultList;
    }

    @Override
    protected boolean createKeys(List<Project> list) {
        for (Project c : projectList) {
            list.add(c);
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(Project p) {
        return new ProjectNode(p);
    }

    void removeProject(Project project) {
        projectList.remove(project);
        refresh(true);
    }

    void addProject(Project project){
        projectList.add(project);
        refresh(true);
    }

    void updateProject(Project project){
        int index = projectList.indexOf(project);
        if (index > 0){
            projectList.set(index, project);
        }
    }
}
